package vn.axonivy.vision.streams;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;



public class StreamBasic {

    public static void main(String...args){
        // Java 7
    	List<String> dishNameList = getDishesNamesGreaterThan500InJava7(Dish.menu);
    	for (String name: dishNameList){
    		System.out.println("Name is: "+name);
    	}
    	
        System.out.println("---"); 

        // Java 8
        getDishesNamesGreaterThan500InJava8(Dish.menu).forEach(d -> System.out.println("Name is: " + d));;

    }

    public static List<String> getDishesNamesGreaterThan500InJava7(List<Dish> paramDishes){
        List<Dish> dishes = new ArrayList<>();
        for(Dish d: paramDishes){
            if(d.getPrice() > 500){
            	
                dishes.add(d);
            }
        }
        List<String> dishNameList = new ArrayList<String>();
        for(Dish d: dishes){
        	dishNameList.add(d.getName());
        }
        
        return dishNameList;
        
    }

    public static List<String> getDishesNamesGreaterThan500InJava8(List<Dish> dishes){
        return dishes.stream()
                .filter(d -> d.getPrice() > 500 || d.isVegetarian())
                .map(Dish::getName)
                .collect(Collectors.toList());
    }
}
